package com.bolt.report.business.modules.field.dto.converter;

import com.bolt.report.business.modules.field.dto.ReportDbFieldDTO;
import com.bolt.report.business.modules.field.entity.ReportDbFieldEntity;

import java.util.Collection;
import java.util.Objects;
import java.util.Set;
import java.util.stream.Collectors;

/**
 * Created by Administrator on 2018/11/27.
 */
public class ReportDbFieldConverter {
    private ReportDbFieldConverter() {
// do nothing
    }

    /**
     * Entity对象转换为DTO对象
     *
     * @param reportDbField DO对象
     * @return DTO对象
     */
    public static ReportDbFieldDTO toDTO(ReportDbFieldEntity reportDbField) {
        if (Objects.isNull(reportDbField)) {
            return null;
        }
        ReportDbFieldDTO result = new ReportDbFieldDTO();
        result.setId(reportDbField.getId());
        result.setReportDbId(reportDbField.getReportDbId());
        result.setFieldName(reportDbField.getFieldName());
        result.setFieldText(reportDbField.getFieldText());
        result.setFieldExpr(reportDbField.getFieldExpr());
        result.setFieldType(reportDbField.getFieldType());
        result.setOrderNum(reportDbField.getOrderNum());
        result.setOrderType(reportDbField.getOrderType());

        // TODO
        return result;
    }

    /**
     * DTO对象转换为Entity对象
     *
     * @param reportDbField DO对象
     * @return VO对象
     */
    public static ReportDbFieldEntity toEntity(ReportDbFieldDTO reportDbField) {
        if (Objects.isNull(reportDbField)) {
            return null;
        }
        ReportDbFieldEntity result = new ReportDbFieldEntity();
        result.setId(reportDbField.getId());
        result.setReportDbId(reportDbField.getReportDbId());
        result.setFieldName(reportDbField.getFieldName());
        result.setFieldExpr(reportDbField.getFieldExpr());
        result.setFieldText(reportDbField.getFieldText());
        result.setFieldType(reportDbField.getFieldType());
        result.setOrderNum(reportDbField.getOrderNum());
        result.setOrderType(reportDbField.getOrderType());
        // TODO
        return result;
    }

    /**
     * DTO对象转换为DO对象
     *
     * @param reportDbField DO对象
     * @return VO对象
     */
    public static ReportDbFieldEntity toEntity(ReportDbFieldEntity result, ReportDbFieldDTO reportDbField) {
        if (Objects.isNull(reportDbField)) {
            return null;
        }
        result.setReportDbId(reportDbField.getReportDbId());
        result.setFieldName(reportDbField.getFieldName());
        result.setFieldExpr(reportDbField.getFieldExpr());
        result.setFieldType(reportDbField.getFieldType());
        result.setFieldText(reportDbField.getFieldExpr());
        return result;
    }



    /**
     * 批量 Entity对象转换为DTO对象
     *
     * @param reportDbFieldList Entity集合对象
     * @return DTO对象
     */
    public static Set<ReportDbFieldDTO> toDTO(Collection<ReportDbFieldEntity> reportDbFieldList) {
        if (Objects.isNull(reportDbFieldList)) {
            return null;
        }
        return reportDbFieldList.stream().map(ReportDbFieldConverter::toDTO).collect(Collectors.toSet());
    }

    public static Set<ReportDbFieldEntity> toEntity(Collection<ReportDbFieldDTO> reportDbFieldList) {
        if (Objects.isNull(reportDbFieldList)) {
            return null;
        }
        return reportDbFieldList.stream().map(ReportDbFieldConverter::toEntity).collect(Collectors.toSet());
    }


}


